<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" >
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>
<div id="formArea">
	<table class="from-table">
		<tr>
			<td class="label">
				<label>用户姓名</label>
			</td>
			<td>
				<input type="text" class="input input-query" name="name" autocomplete="off"/>
			</td>
			<td class="label">
				<label>登录名</label>
			</td>
			<td>
				<input type="text" class="input input-query" name="username" autocomplete="off"/>
			</td>
			<td class="label">
				<label>所属机构</label>
			</td>
			<td>
				<div id="companyId"></div>
			</td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
				<button class="button" id="create"><span>新增</span></button>
			</td>
		</tr>
	</table>
</div>

<div id="table"></div>

<script>


$(function(){

    var cartTypes = [{text:'身份证',value:1},{text:'驾驶证',value:2},{text:'护照',value:3},{text:'军人证',value:4},{text:'港澳身份证',value:5},{text:'台胞证',value:6},{text:'其它',value:7}];

    $('#create').click(function(){
        app.window(layer,{
            area: ['750px', '570px'],
            content: 'user_add.html'
        });
    });

    $('#companyId').search({
        name:'companyId',
        click:function(){
            var index = layer.getFrameIndex(window.name);
            app.window(layer,{
                title:'机构选择',
                btn:[],
                area: ['600px', '600px'],
                content: '../../common/company_tree.html?index=-1&searchId=companyId'
            });
        }
    });

    var company = {"companyId":app.getCompanyId(),"companyId_text":app.getCompanyName()};
    app.resetForm(company);

    $('#query').click(function(){
        console.log('111',app.serializeForm());
        $('#table').datagrid("reload",app.serializeForm());
    });

    function getCartText(value){
        for( var i=0 ; i<cartTypes.length ; i++ ){
            if( cartTypes[i].value == value ){
                return cartTypes[i].text;
			}
		}
	}

    $('#table').datagrid({
        url:app.BASE_API_URL+'user/page',
        columns:[
            {field:'name',title:'用户姓名',width:100},
            {field:'username',title:'登录名',width:100},
            {field:'phone',title:'手机号码',width:100},
            {field:'companyName',title:'所属公司',width:100},
            {field:'cardTypeId',title:'证件类型',width:80,fixed:true,formatter:function (row) {
				return getCartText(row.cardTypeId);
			}},
            {title:'操作',width:120,formatter:function(row){
				return app.getOpt(row.id,'授权','green')+app.getOpt(row.id,'删除','del');
            }}
        ],
		loadSuccess:loadDataSuccess
    });
});

function loadDataSuccess(){
    $('.vui-opt-del').click(function(){
        var row = $(this).parent().parent().parent().data();

        layer.confirm('确定要删除【'+row.name+'】吗？', {icon: 3, title:'提示'}, function(index){
            app.request({
                url:'user/delete',
                data:{id:row.id},
                success:function (resp) {
                    app.actionSuccess_index(resp,index);
                }
            });
        });

	});

    $('.vui-opt-green').click(function(){
        var row = $(this).parent().parent().parent().data();
        app.window(layer,{
            area: 	['500px', '600px'],
            title:'员工授权【'+row.name+'】',
            content: 'user_role.html?id='+row.id+'&companyId='+row.companyId
        });
    });
}
</script>

</body>
</html>